<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
	<meta charset="UTF-8">
    <title>入库申请登记审核子页面</title>
    <link rel="stylesheet"  href="/bootstrap/bootstrap-5.3.3-dist/css/bootstrap.min.css" />
   	<link rel="stylesheet" href="/css/stock/c/Warehousing_Application_Registration.css" />
   <style type="text/css">
    	
    </style>
</head>
<body style="padding: 15px 50px;background-color: #eeeeee;">
	<div class="panel-heading hhead">
		<nav aria-label="breadcrumb">
		  <ol class="breadcrumb">
		  	<span style="color: blue;">您正在做的业务是：</span>
		    <li class="breadcrumb-item"><a href="#">库存管理</a></li>
		    <li class="breadcrumb-item"><a href="#">入库申请管理</a></li>
		    <li class="breadcrumb-item active" aria-current="page">入库申请登记审核</li>
		  </ol>
		</nav>
	</div>
    <form id="FM1">
        <div style="margin-bottom: 2px">
            <div style="display: inline;margin-left: 78%;">
                <input type="radio"  name="checkTag"  value="2"/>未通过
                <input type="radio"  name="checkTag" value="1" checked/>通过
                <input type="hidden" id="HiddenChecker" name="checker" value="">
                <input type="hidden" id="userName" value="${user.loginId}">
                <input type="hidden" id="id" name="id" value="">
                <button type="button" class="btn btn-primary" id="ok">确认</button>
                <button type="button" class="btn btn-primary" id="back">返回</button>
            </div>
        </div> <!-- 此div改用栅格来做 -->
    </form>
    <div id="designListBox">
        <div style="text-align: center">
            <h3>入库申请单</h3>
        </div>
        <div style="padding: 30px">
           <table class="tbl1">
           		<tr>
                   <td class="col1">申请单编号：</td>
                   <td class="col2" id="gatherId"></td>
               </tr>
               <tr>
                   <td class="col1">入库人：</td>
                   <td class="col2" id="storer"></td>
                   <td class="col1">入库理由：</td>
                   <td class="col2" id="reason"></td>
               </tr>
           </table>

            <table class="table table-bordered" style="margin: 15px auto;">
                <thead>
                    <tr>
                        <th>序号</th><th>产品名称</th><th>产品编号</th>
                        <th>描述</th><th>数量</th><th>单位</th>
                        <th>成本单价（元）</th><th>小计（元）</th>
                    </tr>
                </thead>
                <tbody id="template">

                </tbody>

            </table>

            <table class="tbl3">
            	<tr>
                    <td class="col1">总件数：</td>
                    <td class="col2" id="amountSum"></td>
                    <td class="col1">总金额：</td>
                    <td class="col2" id="costPriceSum"></td>
                </tr>
                <tr>
                    <td class="col1">登记人：</td>
                    <td class="col2"><input type="text" class="txt_under_line" id="Registrants"></td>
                    <td class="col1">登记时间：</td> <td class="col2" id="time"></td>
                </tr>
                <tr>
                    <td class="col1">审核人：</td>
                    <td class="col2"><input type="text" class="txt_under_line" id="checker"></td>
                    <td class="col1">审核时间：</td> <td class="col2" id="checkTime"></td>
                </tr>
                <tr>
                    <td class="col1">备注：</td>
                    <td colspan="3" style="padding-top: 5px">
                        <textarea rows="4" cols="100" id="moduleDescribe"></textarea>
                    </td>
                </tr>
            </table>
        </div>
    </div>
    
    <div class="modal fade" id="proRegistraModal" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="staticBackdropLabel" aria-hidden="true">
			<div class="modal-dialog modal-xl">
					<div class="modal-content">
						<div class="modal-header">
							<h2>添加产品</h2>
							<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
						</div>
						<div class="modal-body">
							<div class="container-fluid">
								<div id="bodyBox">
									<form>
										<div class="panel product">
											<div class="panel-heading hhead">
												<nav aria-label="breadcrumb">
												  <ol class="breadcrumb">
												  	<span style="color: blue;">您正在做的业务是：</span>
												    <li class="breadcrumb-item"><a href="#">库存管理</a></li>
												    <li class="breadcrumb-item"><a href="#">入库申请管理</a></li>
												    <li class="breadcrumb-item active" aria-current="page">入库申请登记</li>
												  </ol>
												</nav>
												<div>
													<p><small>当前等待复核的配置单总数：<span style="color: red;">2</span>例</small></p>
												</div>
											</div>
											
											<div class="panel-body bbody">
												<table id="tab" >
													<thead>
														<tr style="background-color: #e8e8e8;">
															<td>产品编号</td>
															<td>产品名称</td>
															<td>用途类型</td>
															<td>单位</td>
															<td>成本单价</td>
															<td>入库</td>
														</tr>
													</thead>
													<tbody>

													</tbody>
												</table>
											</div>
											
											<div class="panel-footer ffooter">
												<div id="footerDiv">
													<label style="font-weight: 700;">总数：<span style="color: red;">5</span>例&nbsp;&nbsp;&nbsp;&nbsp;
														当前第<span style="color: red;">1</span>页&nbsp;&nbsp;&nbsp;&nbsp;
														共<span style="color: red;">1</span>页&nbsp;&nbsp;&nbsp;&nbsp;
													</label>
												</div>
											</div>
										</div>
									</form>
								</div>
							</div>
						</div>
						<div class="modal-footer">
							<button id="btnConcel" class="btn btn-danger" data-bs-dismiss="modal">
								关闭<span class="glyphicon glyphicon-remove"></span>
							</button>
						</div>
					</div>
				</div>
		</div>
		
    <script type="text/javascript" src="/js/jquery-3.7.0.min.js"></script>
    <script type="text/javascript" src="/bootstrap/bootstrap-5.3.3-dist/js/bootstrap.bundle.min.js"></script>
    <script type="text/javascript" src="/js/common.js"></script>
    <script type="text/javascript">
        $(function (){
            // 初始化数据
            ItemApprovalTable();

            // 初始化时间
            setInterval(updateDateTime, 1000);

            $("#back").on("click",function (){
                event.defaultPrevented
                sessionStorage.clear();
                window.location.href="/s-gather/warehousing_application_review";
            })

            $("#ok").click(function (){
                let b = confirm("确认审核吗？(以最后一次确认的结果为准)",Audit,"确认","取消");
                if (b){
                    Audit();
                }
                return false;
            })
        })
        function ItemApprovalTable(){
            let id = sessionStorage.getItem("id");
            $("#id").val(id);
            $.ajax({
                url: "/s-gather/ItemApprovalTable?id="+id,
                type: "GET",
                dataType: "json",
                success: function (data) {
                    console.log(data);
                    if (data.errCode == "1") {
                        alert(data.errMsg)
                    } else {

                        $("#gatherId").text(data.gatherId);
                        $("#storer").text(data.storer);
                        $("#reason").text(data.reason);
                        $("#amountSum").text(data.amountSum);
                        $("#costPriceSum").text(data.costPriceSum);
                        $("#Registrants").val(data.register);
                        $("#time").text(data.registerTime);
                        $("#moduleDescribe").val(data.remark);
                        initialTemplate(data.id);
                    }
                }
            })
        }
        function initialTemplate(parentId){
            $.ajax({
                url: "/s-gather/initialTemplate?id="+parentId,
                type: "GET",
                dataType: "json",
                success: function (data) {
                    console.log(data);
                    if (data.errCode == "1") {
                        alert(data.errMsg)
                    } else {
                        let template = $("#template");
                        // 清空表格
                        template.empty();
                        // 遍历数据并添加到表格中
                        data.forEach(function (item, index) {
                            let row = $("<tr>");
                            row.append($("<td>").text(index + 1));
                            row.append($("<td>").text(item.productName));
                            row.append($("<td>").text(item.productId));
                            row.append($("<td>").text(0));
                            row.append($("<td>").text(item.amount));
                            row.append($("<td>").text(item.amountUnit));
                            row.append($("<td>").text(item.costPrice));
                            row.append($("<td>").text(item.subtotal));
                            template.append(row);
                            $("#productId").val(item.productId);
                        })

                    }
                }
            })
        }
        function Audit() {
            let checker = $("#checker").val()
            if (checker == ""){
                $("#HiddenChecker").val($("#userName").val())
                $("#checker").val($("#userName").val())
            } else {
                $("#HiddenChecker").val(checker)
            }
            let json = formDateToJson("FM1");
            console.log(json);
            sessionStorage.clear();
            $.ajax({
                url: "/s-gather-details/Audit",
                type: "POST",
                data: json,
                dataType: "json",
                contentType: "application/json",
                success: function (data){
                    if (data.errCode == "1") {
                        alert(data.errMsg)
                    } else {
                        if(data){
                            alert("审核通过！");
                            window.location.href="/s-gather/initialWarehousingTable";
                        }else {
                            alert("提交失败");
                        }
                    }
                }

            })
            sessionStorage.clear();
        }
        function updateDateTime(){
            let date = new Date();
            let year = date.getFullYear();
            let month = (date.getMonth() + 1).toString().padStart(2, '0');
            let day = date.getDate().toString().padStart(2,'0');
            let hours = date.getHours().toString().padStart(2,'0');
            let minutes = date.getMinutes().toString().padStart(2,'0');
            let seconds = date.getSeconds().toString().padStart(2,'0');
            let dateTimeStr = year+"-"+month+"-"+day+" "+hours+":"+minutes+":"+seconds;
            $("#checkTime").text(dateTimeStr);
        }
    </script>
</body>
</html>
